package com.zrrd.learn.chapter09.collectlianxi;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Worker测试类
 *
 * @author wrn
 * @version 1.0
 * @date 2023/8/18 15:34
 */

public class collect05 {

    public static void main(String[] args) {

        List<Worker> list = new ArrayList<>();
        Worker w1 = new Worker("zhang3",18,3000);
        Worker w2 = new Worker("l14",25,6000);
        Worker w3 = new Worker("wang5",22,9999);
        Worker w4 = new Worker("zhao6",24,10000);

        list.add(w1);
        list.add(w2);
        list.add(w3);
        list.forEach(System.out::println);
        list.add(1,w4);

        list.forEach(System.out::println);

        list.remove(w3);
        list.forEach(System.out::println);

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        Iterator<Worker> it = list.iterator();
        for (; it.hasNext();) {
            Worker obj = it.next();
            obj.work();
            System.out.println(obj);
        }





    }

}
